home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / CALENDAR.AML < prev    next >
Text File  |  1996-07-17  |  4KB  |  195 lines

  1. //--------------------------------------------------------------------
  2. // CALENDAR.AML
  3. // Popup Calendar, (C) 1993-1996 by nuText Systems
  4. //
  5. // (See Calendar.dox for user help)
  6. //
  7. // This macro displays a calendar window for the current year and month.
  8. // The current day is highlighted.
  9. //
  10. // This macro also calls Cfg\Cfgintnl.x.
  11. //
  12. // Usage:
  13. //
  14. // Select this macro from the Macro List (on the Macro menu), or run it
  15. // from the macro picklist <shift f12>.
  16. //--------------------------------------------------------------------
  17.  
  18. include bootpath "define.aml"
  19.  
  20. // define the colors to use
  21. constant cal_client_color   = color black       on gray
  22. constant cal_border_color   = color white       on gray
  23. constant cal_bordera_color  = color brightgreen on gray
  24. constant cal_title_color    = color brightblue  on gray
  25. constant cal_today_color    = color brightgreen on gray
  26. constant cal_control_color  = color yellow
  27.  
  28. // current year and month
  29. variable year, month
  30.  
  31. // keep this object resident
  32. resident ON
  33. settype "win"
  34.  
  35. constant daynames = 1
  36. constant monthnames = 2
  37.  
  38. // get day/month names
  39. names = runmacro (bootpath "cfg\\cfgintnl.x") '' 'n'
  40. months = names.monthnames
  41. dayheader = ' '
  42. for i = 1 to 7 do
  43.   dayheader = dayheader + names.daynames [i][1..3] + '  '
  44. end
  45.  
  46. // function to redraw the calendar for any year and month
  47. private function  draw
  48.   variable monthdays
  49.  
  50.   // set the calendar title based on the year and month
  51.   settitle months [month] + " " + year  'c'
  52.  
  53.   // get the day in which the year starts using a perpetual
  54.   // calendar (0-6, 0=sunday)
  55.   startday = "5012356013456123460124560234" [year mod 28 + 1]
  56.  
  57.   // string indicating the days over 28 for each month
  58.   over28 = concat (if? (not (year mod 4)) "31" "30") "3232332323"
  59.  
  60.   // get total days in the month
  61.   maxdays = 28 + over28 [month]
  62.  
  63.   // get the number of days in previous months
  64.   for i = 1 to month - 1 do
  65.     monthdays = monthdays + 28 + over28 [i]
  66.   end
  67.  
  68.   // calculate the starting day for the month (0-6, 0=sunday)
  69.   startday = (startday + monthdays) mod 7
  70.  
  71.   // set 'today' to today's day number if it's the right
  72.   // year and month
  73.   rawtime = getrawtime
  74.   today = if rawtime [5:2] == month and rawtime [1:4] == year then
  75.             rawtime [7:2]
  76.           end
  77.  
  78.   // clear the window and draw the header
  79.   gotoxy 1 1
  80.   fillrect (getviewcols) (getviewrows)
  81.   writeline dayheader cal_title_color
  82.  
  83.   // move the video cursor to the start-day position
  84.   gotoxy 2 + startday * 5
  85.  
  86.   // write the calendar days
  87.   for day = 1 to maxdays do
  88.     writestr day:3 + "  "
  89.       (if? day == today  cal_today_color  cal_client_color)
  90.     if getx > 34 then
  91.       writeline
  92.       writestr ' '
  93.     end
  94.   end
  95.  
  96. end
  97.  
  98. // create the calendar window
  99. createwindow
  100. setframe ">b"
  101. setwinctrl '≡'
  102. setshadow 2 1
  103.  
  104. width = 35
  105. height = 6
  106.  
  107. // center the window
  108. ox = (getvidcols - width) / 2
  109. oy = (getvidrows - height) / 2
  110. sizewindow ox oy ox + width oy + height "ad"
  111.  
  112. setborder "1i"
  113. setcolor  border_color         cal_border_color
  114. setcolor  border_flash_color   cal_bordera_color
  115. setcolor  text_color           cal_client_color
  116. setcolor  control_color        cal_control_color
  117.  
  118. // current year and month
  119. year  = getrawtime [1:4]
  120. month = getrawtime [5:2]
  121.  
  122. // redraw the calendar window
  123. draw
  124.  
  125. event <destroy>
  126.   // call 'close' in object 'win'
  127.   close
  128. end
  129.  
  130. // macro help
  131. macrofile = arg 1
  132. key <f1>
  133.   helpmacro macrofile
  134. end
  135.  
  136. function "≡"  destroyobject
  137. key <esc>     destroyobject
  138.  
  139. // mouse click
  140. key <lbutton>
  141.   case getregion
  142.     // close icon
  143.     when 51
  144.       destroyobject
  145.     otherwise
  146.       pass
  147.   end
  148. end
  149.  
  150. // forward one month
  151. key <pgdn>
  152.   month = month + 1
  153.   if month > 12 then
  154.     month = 1
  155.     year = year + 1
  156.   end
  157.   draw
  158. end
  159.  
  160. // backward one month
  161. key <pgup>
  162.   month = month - 1
  163.   if not month then
  164.     month = 12
  165.     year = year - 1
  166.   end
  167.   draw
  168. end
  169.  
  170. // goto january
  171. key <ctrl pgup>
  172.   month = 1
  173.   draw
  174. end
  175.  
  176. // goto december
  177. key <ctrl pgdn>
  178.   month = 12
  179.   draw
  180. end
  181.  
  182. // forward one year
  183. key <right>
  184.   year = year + 1
  185.   draw
  186. end
  187.  
  188. // backward one year
  189. key <left>
  190.   if year then
  191.     year = year - 1
  192.   end
  193.   draw
  194. end
  195.